package com.h2210c.user.controller;

import com.h2210c.user.fenig.ListCompetitionMemberService;
import com.h2210c.user.fenig.ListCourseService;
import com.h2210c.user.fenig.ListMemberService;
import com.h2210c.user.fenig.ListTrainingService;

import com.h2210c.user.service.MemberService;
import com.h2210c.user.utis.AppJwtUtil;
import com.jiyun.model.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("user")
public class MemberController {
    @Autowired
    MemberService memberService;
    @Autowired
    ListMemberService listMemberService;
    @Autowired
    ListTrainingService listTrainingService;
    @RequestMapping("login")
    public Result login(@RequestBody Member member){

        Member one = listMemberService.login(member);
        if (one==null){
            return Result.EOER(500,"账号错误");
        }
        if (!one.getPassword().equals(member.getPassword())){
            return Result.EOER(500,"密码错误");
        }
        Map map= new HashMap<>();
        map.put("token", AppJwtUtil.getToken(Long.valueOf(one.getId())));
        map.put("user",one);
        return Result.OK(200,map);
    }

@RequestMapping("kecheng")
public List<Course> findtraining(@RequestParam("id") Integer id){
    List<Course> findtraining = listTrainingService.findtraining(id);
    return findtraining;
}
    @RequestMapping("peixun")
    public List<TrainingMember> jingsai(@RequestParam("id") Integer id){
       return listTrainingService.jingsai(id);
    }
    @Autowired
    ListCompetitionMemberService listCompetitionMemberService;
    @RequestMapping("jingsai")
    public List<CompetitionMember> jingsai1(@RequestParam Integer id){
      return   listCompetitionMemberService.jingsai(id);
    }
    @Autowired
    ListCourseService listCourseService;
    @RequestMapping("dianzhan")
    public void dianzhan(@RequestParam Long id){
        listCourseService.dianzhan(id);
    }

    @RequestMapping("list")
    public List<Course> list(){
      return listCourseService.list();
    }
    @RequestMapping("num")
    public void num(){
        listTrainingService.num();;
    }


}
